// Agent supplier in project publicprintingwithjason

/* Initial beliefs and rules */

/* Initial goals */

/* Plans */

//if the supplier is not currently delivering supplies
//and there are no printer in the queue waiting for supplies
//it will walk to the printer and make the delivery
@psupply[atomic]
+!supply(P)[source(P)] : not delivering(_) & not needsupplies(_)
  <-
  	+delivering(P);
  	!!walkto(P).
  
//if the supplier is on his way to delivery supplies to a printer,
//it will add this new request to a queue, in order to deliver later
@psupply2[atomic]
+!supply(P)[source(P)] : true
  <-
  	+needsupplies(P).

//this plans is responsible to guide the supplier to a printer
+!walkto(P) : not at(P)
	<-
	walkto(P);
	!!walkto(P).	

//as soon as the supplier arrives at the printer it will deliver the supplies
//and if there are more printers waiting for supplies it will deliver to them
//otherwise it will go back home	
+!walkto(P) : at(P)
	<-
	.print("Delivering supplies to ", P);
	.send(P, tell, supplies(3));
	-delivering(P);
	-needsupplies(P);
	!!nextdelivery.

//if there are more printers waiting for supplies, go to them and make the delivery
+!nextdelivery : needsupplies(P)
	<-
	+delivering(P);
  	!!walkto(P).
  
//if there are no printers needing supplies, go back home
+!nextdelivery : true
	<-
	gohome.
